package com.sz.biz.logistics.serialno.service.impl;

import com.sz.biz.logistics.serialno.entity.VerifyRules;
import com.sz.biz.logistics.serialno.service.VerifyRuleService;
import com.sz.common.base.dao.ParamData;
import com.sz.common.base.dto.QResultDto;
import com.sz.common.base.dto.QueryParams;
import com.sz.common.base.service.AbstractService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Function: 校验规则相关功能实现 <br>
 * Author: Johnboy <br>
 * Date: 2017-12-07 19:07:00
 */
@Service
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
public class VerifyRuleServiceImpl extends AbstractService implements VerifyRuleService{

    @Override
    protected String getMapperNamespace(){
        return "VerifyRulesMapper";
    }

    @Override
    public QResultDto query(QueryParams queryParams){
        ParamData paramData = this.convertQueryParams(queryParams);
        List<VerifyRules> verifyRules = dao.findForList(getSqlName("findByParamListPage") , paramData , VerifyRules.class);
        QResultDto qResultDto = new QResultDto();
        qResultDto.setPagination(paramData.getPagination());
        qResultDto.setData(verifyRules);
        return qResultDto;
    }
    
    @Override
    public String selectRegexByRuleCode(String ruleCode) {
        return String.valueOf(dao.findForObject(getSqlName("selectRegexByRuleCode"), ruleCode));
    }

    @Override
    public VerifyRules selecByRuleCode(String ruleCode) {
        return (VerifyRules)dao.findForObject(getSqlName("selectByRuleCode"), ruleCode);
    }

    @Override
    public List<VerifyRules> queryByType(int type) {
        return dao.findForList(getSqlName("queryByType"),type,VerifyRules.class);
    }
}
